home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Guide 18
/
PC Guide CD-ROM (PCCD-18-12-96) (1996).iso
/
cylindrx
/
clock
/
iweb.wil
< prev
next >
Wrap
Text File
|
1996-08-29
|
5KB
|
185 lines
;******** Web client sample Winsock app ********
szTitle = "Charlie Cursor's Neat-O Web Browser"
szDial = "%param1%"
szHost = "%param2%"
szPort = "80"
hSock = 0
;Dial our host...
hConn = SDialUp (szDial)
if (!hConn)
exit
endif
; This is our "browser"...
if (!WinExist (szTitle))
Run ("notepad.exe","%szTitle%.")
if (WinExistChild ("Notepad", "Cannot find the %szTitle%. file"))
SendKeysTo ("Notepad", "~")
endif
SendKeysTo (szTitle, "!ew") ; Turn on word-wrap
else
; Clear the existing browser window...
SendKeysTo (szTitle, "!ea{del}")
endif
; Main command loop...
szURL = "http://%szHost%/"
szURLList = ""
while (szURL<>"")
; Get the URL...
szURLList = ItemInsert ("<end>", -1, szURLList, @TAB)
szURLList = ItemInsert ("<new>", -1, szURLList, @TAB)
szURL = AskItemList ("Choose the URL, <new>, or <end>:", szURLList, @TAB, @Unsorted, @Single)
if (szURL=="<end>" || szURL=="")
goto HangUp
endif
if (szURL=="<new>")
szURL = AskLine (szTitle, "Enter the URL:", szURL)
endif
gosub SplitURL
; Clear our browser window...
SendKeysTo (szTitle, "!ea{del}")
; Create a socket...
hSock = SOpen (@SBlocking)
if (hSock==@SErrSocket)
Message (szTitle, "Couldn't create socket.")
goto HangUp
endif
; Connect it up...
nRet = SConnect (hSock, szHost, szPort)
if (nRet <> @TRUE)
nErr = SGetLastErr ()
Message (szTitle, "Error connecting socket to %szHost%:%szPort% %@CRLF% %nErr%")
goto CloseSocket
endif
; Send our HTTP request...
szCmd = "GET %szFile% HTTP/1.0"
nRet = SSendLine (hSock, szCmd)
nRet = SSendLine (hSock, "") ; Blank line ends an HTTP request
if (nRet<>@SOK)
nErr = SGetLastErr()
Message (szTitle, "Error sending command: %nErr%")
goto CloseSocket
endif
; Get the HTTP headers...
szHeader = ""
szLine = SRecvLine (hSock, 32767)
nErr = SGetLastErr()
while (nErr<>@SErrNoConn)
if (nErr == @SOK)
szHeader = StrCat (szHeader, szLine, @CRLF)
endif
Yield ()
szLine = SRecvLine (hSock, 32767)
nErr = SGetLastErr()
endwhile
; Just for fun, display ea. header line in our browser window...
ClipPut (szHeader)
SendKeysTo (szTitle, "^v~")
; Get the actual data (many lines, but delim with single LF
; so it's really all one big string)...
szPage = ""
while (nErr <> @SErrNoConn)
szLine = SRecvLine (hSock, 32767)
nErr = SGetLastErr ()
if (nErr == @SOK)
; Now display it in our browser window...
szLine = strreplace (szLine, num2char(10), @CRLF)
if (strright(szPage,2) <> @CRLF)
szLine = StrCat (szLine, @CRLF)
endif
szPage = StrCat (szPage, szLine)
endif
Yield ()
endwhile
; Extract the links from this page...
gosub ParsePage
ClipPut (szPage)
SendKeysTo (szTitle, "^v~")
; Close the socket...
:Cancel
:CloseSocket
if (hSock <> 0)
nRet = SClose (hSock)
endif
endwhile
; Hang up...
:HangUp
nRet = SHangUp (hConn)
exit
;**************************************************************************
; Split up szURL into szHost & szFile.
;**************************************************************************
:SplitURL
nSUStart = 1
if (strindex (szURL, "http://", 1, @FWDSCAN) == 1)
nSUStart = 8
endif
nSUSlash = strindex (szURL, "/", nSUStart, @FWDSCAN)
if (nSUSlash == 0)
szURL = strcat (szURL, "/")
nSUSlash = strlen(szURL)
endif
if (nSUSlash <> 1)
szHost = strsub (szURL, nSUStart, nSUSlash-nSUStart)
endif
szFile = strsub (szURL, nSUSlash, strlen(szURL)-nSUSlash+1)
return
;**************************************************************************
; Extract all the hyperlinks from szPage into szURLList.
;**************************************************************************
:ParsePage
nPPH = 1
nPPQ2 = 1
szURLList = ""
nPPLen = StrLen(szPage)
Message (szTitle, "szPage is %nPPLen% chars long.")
if (nPPLen < 5)
return
endif
while (nPPQ2 > 0)
nPPH = StrIndex (szPage, "HREF=", nPPQ2, @FWDSCAN)
if (nPPH > 0)
Message (szTitle, "HREF= found at %nPPH%")
nPPQ1 = StrIndex (szPage, '"', nPPH+5, @FWDSCAN)
if (nPPQ1 > 0)
Message (szTitle, '1st " found at %nPPQ1%')
nPPQ2 = StrIndex (szPage, '"', nPPQ1+1, @FWDSCAN)
if (nPPQ2 > 0)
Message (szTitle, '2nd " found at %nPPQ2%')
szPPURL = StrSub (szPage, nPPQ1+1, nPPQ2-nPPQ1-1)
Message (szTitle, "szPPURL = %szPPURL%")
szURLList = ItemInsert (szPPURL, -1, szURLList, @TAB)
endif
endif
endif
endwhile
return